/**
 * Created by LIUBA2 on 8/23/2016.
 */
const mongoose=require("mongoose");
const request=require("request");

var config=require("../config/config.js")

var Food=mongoose.model("food");

exports.getFoods=function (req,res) {
    if((typeof req.query.mId) !="undefined"){
        console.log(req.query.mId)
        Food.find()
            .where("mId").equals(req.query.mId)
            .exec(function (err, foods) {
                if(!err){
                    res.json(foods)
                }else{
                    res.json({error:"getFoods"})
                }
            })
    }else{
        request(config.wsGetRecommendFoodUrl,function (err, response, body) {
            var b=JSON.parse(body);
            // b=[{"_id":"57b70431652b69f4d8e44b70","fId":9,"fName":"jiaShuJu","mId":6,"fViewPath":"wrewf","fStatus":3}];
            // console.log("wsGetRecommendFoodUrl:----"+body);
            // Food.find()
            //     .where("mId").equals("57beaa3937be69740401b959")
            //     .exec(function (err, foods) {
            //         if(!err){
            //             res.json(foods)
            //         }else{
            //             res.json({error:"getFoods"})
            //         }
            //     })
            console.log(b);
            res.json(b);
        })
    }
}